package org.apache.dubbo.demo.example.eg13;

import java.util.concurrent.CompletableFuture;
import java.util.concurrent.TimeUnit;

public class AsyncServiceImpl implements AsyncService {

  @Override
  public CompletableFuture<String> sayHello(String name) {
    return CompletableFuture.supplyAsync(() -> {
      System.out.println("************************** sayHello() invoked **************************");
      sleep(2);
      return "hello, " + name;
    });
  }

  private void sleep(int seconds) {
    try {
      TimeUnit.SECONDS.sleep(seconds);
    } catch (InterruptedException e) {
      e.printStackTrace();
    }
  }
}
